package com.ruoyi.system.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {
    @Autowired
    private IIbrainTaskService ibrainTaskService;

    @Autowired
    private IScaleRecordService scaleRecordService;
    @Autowired
    private IAllTaskService iAllTaskService;
    @Autowired
    private IMriqcConfigService mriqcConfigService;
    @Autowired
    private IIstrokeConfigService iIstrokeConfigService;

    //3.添加定时任务
    @Scheduled(cron = "0/10 * * * * ?")
    @Async
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    protected void configureTasks() throws InterruptedException, JsonProcessingException {
        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
        ibrainTaskService.updatemanyibraintaskstatus();
        ibrainTaskService.runstatus2to3();

        //电子量表生成
        scaleRecordService.handelscale_v2();

        iAllTaskService.updatemanytaskstatus();  //总任务更新状态
        //MRIQC
        mriqcConfigService.runstatus2to3();
        //istroke
        iIstrokeConfigService.runstatus2to3();


    }


}
